#include "VerticalStair.h"
#include "AnimationFilmHolder.h"

void VerticalStair::UpStepCompleted (Animator* _animator, void* closure) {
	AnimatorData* data = (AnimatorData*) closure;
	Sprite *s = data->first;
	Stair *stair = data->second;
	s->SetPlatform(stair->GetTopPlatform());
	s->EnableMovement();
	s->DisableClimbing();
	((Platform*)s->GetPlatform())->AlignWithPlatform(s);
	AnimatorHolder::DelayedSuspention(_animator);
	//delete data;
};

void VerticalStair::DownStepCompleted (Animator* _animator, void* closure) {
	AnimatorData* data = (AnimatorData*) closure;
	Sprite *s = data->first;
	Stair *stair = data->second;
	s->SetPlatform(stair->GetBottomPlatform());
	s->EnableMovement();
	s->DisableClimbing();
	((Platform*)s->GetPlatform())->AlignWithPlatform(s);
	AnimatorHolder::DelayedSuspention(_animator);
	//delete data;
};

void VerticalStair::AnimateUp(Sprite *s)  {
	if(animator->HasFinished()) {
		//s->SetAnimationFilm((AnimationFilm *)AnimationFilmHolder::GetSingleton()->GetFilm("popeye_climb_vertical"));
		s->DisableMovement(); //player should not be allowed to move during the animation
		animator->SetOnFinish(UpStepCompleted, new AnimatorData(s, this));
		animator->Start(s, up, Timer::getgametime());
		AnimatorHolder::MarkAsRunning(animator);
	}
};

void VerticalStair::AnimateDown(Sprite *s)  {
	if(animator->HasFinished()) {
		//s->SetAnimationFilm((AnimationFilm *)AnimationFilmHolder::GetSingleton()->GetFilm("popeye_climb_vertical"));
		s->DisableMovement(); //player should not be allowed to move during the animation
		animator->SetOnFinish(DownStepCompleted, new AnimatorData(s, this));
		animator->Start(s, down, Timer::getgametime());
		AnimatorHolder::MarkAsRunning(animator);
	}
};

void VerticalStair::AlignUp (Sprite* s) {
	Rect *stair_rect = this->GetTopStep()->GetRect();
	s->SetX(stair_rect->x+2);
	s->SetY(stair_rect->y+stair_rect->h-s->GetRect().h);

};
	
void VerticalStair::AlignDown (Sprite* s) {
	Rect *stair_rect = this->GetTopStep()->GetRect();
	s->SetX(stair_rect->x+2);
};
